package asia.lxq.cic.controller;

import asia.lxq.cic.config.GlobalConfig;
import asia.lxq.cic.entity.*;
import asia.lxq.cic.service.ActivityService;
import asia.lxq.cic.service.ArticleService;
import asia.lxq.cic.service.CommentService;
import asia.lxq.cic.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/browse")
public class BrowserController {

    @Autowired
    ArticleService articleService;
    @Autowired
    NoticeController noticeController;
    @Autowired
    CommentService commentService;
    @Autowired
    ActivityService activityService;
    @Autowired
    RedisUtil redisUtil;

    @GetMapping("/article_detail")
    public Result<Article> getArticleDetail(int articleId){
        return articleService.getArticleDetail(articleId);
    }

    @GetMapping("/comment/article_comment_list")
    public Result<List<Comment>> getCommentListByArticle(int articleId){
        return Result.buildOrigin(StatusCode.OK,commentService.getCommentListByArticle(articleId),"成功",true);
    }

    @GetMapping("/article/article_college")
    public Result<Map<String, Object>> getArticleListByCollegeId(int collegeId, int page, int pageSize){
        return articleService.getArticleListOfArea(collegeId, page, pageSize);
    }

    //todo 只能获取全国和学院范围的公告
    @GetMapping("/notice_list")
    public Result<Object> getLastNotice(@RequestParam(required = false,defaultValue = "college")String column,
                                        @RequestParam(required = false,defaultValue = "0")int value,
                                        @RequestParam(required = false,defaultValue = "1") int page,
                                        @RequestParam(required = false,defaultValue = "10")int pageSize){
        return noticeController.getLastNotice(column, value, page, pageSize);
    }

    @GetMapping("/activity/get_activity")
    public Result<Activity> getActivityById(int activityId){
        return Result.success(activityService.getActivityById(activityId));
    }

    @GetMapping("/activity/activity_list")
    public Result<Object> getActivityList(@RequestParam(defaultValue = "1",required = false) int page,
                                          @RequestParam(defaultValue = "10",required = false) int pageSize,
                                          @RequestParam(defaultValue = "0",required = false) int collegeId,
                                          @RequestParam(defaultValue = "0",required = false) int groupId){
        return activityService.getActivityList(collegeId,groupId, page, pageSize);
    }
}
